// pages/luck-draw-details/luck-draw-details.js
var o, WxParse = require("../../wxParse/wxParse.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    is_new_user:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (t) {
    getApp().page.onLoad(this, t)
    o = this
    o.user_status()
    var list = JSON.parse(decodeURIComponent(t.item))
    console.log(t,list)
    WxParse.wxParse("detail", "html", list.prize.detail, o),
      o.setData({
        list: list
      })
  },
  user_status: function (e) {
    var o = this
     getApp().request({
       url: getApp().api.default.user_status,
       success: function (e) {
         o.setData({
           is_new_user: e.data.is_new_user
         })
       },
       complete: function () {
         getApp().core.hideLoading();
       }
     });
   },
  sign: function (e) {
    if (!o.data.is_new_user && o.data.list.is_open == 1) {
      getApp().core.showModal({
        title: '您还未成为99会员，点击确认即可成为99会员。',
        success: function (e) {
          e.confirm && (wx.navigateTo({
            url: '/pages/Nineactivities/Nineactivities',
          }))
        }
      })
      return;
    }
    getApp().request({
      url: getApp().api.integral_lottery.sign,
      data: {
        activity_id: o.data.list.id
      },
      success: function (r) {
        console.log('人气好物', r)
        if (r.code === 0) {
          wx.showToast({
            title: '参与成功，待开奖',
            icon: 'success',
            duration: 2000
          })
          o.setData({
           'list.is_join': '1',
           'list.join_num':o.data.list.join_num + 1
          })
        }else{
          wx.showToast({
            title: r.msg,
            icon: 'success',
            duration: 2000
          })
        }
      },
      complete: function (r) {
        getApp().core.hideLoading();
      }
    });
  },
})